﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cofe.Core.Utils;

namespace Cofe.Core.Filter
{
    [EntryFilter("source")]
    public class SearchSourceOptionFilter : OptionFilterBase, ISearchSourceOptionFilter
    {
        #region Constructor

        public SearchSourceOptionFilter(
             SearchSourceType searchSource = SearchSourceType.All,
             string id = "source")
            : base(searchSource.ToString(), id)
        {
            _searchSource = searchSource;
        }

        private static SearchSourceType parseSearchSource(string searchSourceString)
        {
            switch (searchSourceString.ToLower())
            {
                case "fs":
                    return SearchSourceType.FileSystem;
                case "db":
                    return SearchSourceType.Cache;
            }

            SearchSourceType searchSource;

            if (EnumUtils<SearchSourceType>.EnumTryParse(searchSourceString,
                out searchSource))
                return searchSource;

            return SearchSourceType.All;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="searchSourceString">FileSystem, fs, Cache, db, All</param>
        public SearchSourceOptionFilter(string searchSourceString, 
            string id = "source")
            : this(parseSearchSource(searchSourceString), id)
        {
        }

        #endregion

        #region Methods

        #endregion

        #region Data

        SearchSourceType _searchSource;

        #endregion

        #region Public properties

        public SearchSourceType SearchSource { get { return _searchSource; } }

        #endregion
    }
}
